#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> memory(m, 0);
    // （标识符，（起始位置，大小））
    unordered_map<int, pair<int, int>> tag;
    set<int> tags;
    int id = 1;
    while(n--){
        string op;
        cin >> op;
        if(op == "alloc"){
            int newmemory;
            cin >> newmemory;
            bool isFree = 0;
            int freecnt = 0, freepos = -1;
            // 寻找空位
            for(int i = 0; i < m; ++i){
                if(memory[i] == 0){
                    if(++freecnt >= newmemory){
                        isFree = 1;
                        ++freepos;
                        break;
                    }
                }else{
                    freecnt = 0;
                    freepos = i;
                }
            }
            // 没空位
            if(!isFree){
                cout << "NULL" << endl;
                continue;
            }
            //有空位-改memory、添加标识符定位和集合
            for(int i = freepos; i < min(freepos + newmemory, m); ++i){
                memory[i] = 1;
            }
            tag[id] = pair<int, int>({freepos, newmemory});
            tags.insert(id);
            cout << id++ << endl;
        }else if(op == "erase"){
            int nowtag;
            cin >> nowtag;
            // 没有这个标识符
            if(tags.find(nowtag) == tags.end()){
                cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
                continue;
            }
            // 有：删内存、删标识符定位和集合
            int delpos = tag[nowtag].first;
            int delsize = tag[nowtag].second;
            for(int i = delpos; i < min(delpos + delsize, m); ++i){
                memory[i] = 0;
            }
            tag.erase(nowtag);
            tags.erase(nowtag);

        }else if(op == "defragment"){
            if(tags.size() == 0) continue;
            vector<int> pathtag;
            for(int t : tags){
                pathtag.push_back(t);
            }
            sort(pathtag.begin(), pathtag.end(), [&](int a, int b){
                return tag[a].first < tag[b].first;
            });
            // 清空
            fill(memory.begin(), memory.end(), 0);
            int s = pathtag.size();
            int nowpos = 0, lastpos = 0;
            for(int i = 0; i < s; ++i){
                int usedmemory = tag[pathtag[i]].second;
                tag[pathtag[i]].first = nowpos;
                for(;nowpos - lastpos < usedmemory; ++nowpos){
                    memory[nowpos] = 1;
                }
                lastpos = nowpos;
            }
        }
    }

}